package com.shujia.wyh;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class HiveJDBCDemo {
    public static void main(String[] args) throws Exception {
        //注册hive的驱动
        Class.forName("org.apache.hive.jdbc.HiveDriver");
        //创建与hive服务器的连接对象
        //windows：客户端 ----> hiveserver2：服务器端
        Connection conn = DriverManager.getConnection("jdbc:hive2://master:10000/bigdata23");
        //创建执行sql语句的对象
        Statement stat = conn.createStatement();
        ResultSet rs = stat.executeQuery("select t1.empno as empno,t2.deptno as deptno,t2.dname as dname from emp t1 join dept t2 on (t1.deptno=t2.deptno)");
        while (rs.next()) {

            int empno = rs.getInt(1);
            String deptno = rs.getString(2);
            String dname = rs.getString(3);
            System.out.println(empno+","+deptno+","+dname);
        }
        rs.close();
        stat.close();
        conn.close();
    }
}
